package com.teamclub.domain.system;

import io.ebean.Ebean;
import io.ebean.Finder;
import io.ebean.Model;
import com.google.common.collect.Lists;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Transient;
import java.util.List;

/**
 * Created by ilkkzm on 17-8-9.
 */
@Entity
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
@Data
public class AppFuncTree extends Model{
    @Id
    private Integer id;
    private String name;
    private String path;
    private Integer parentId;
    private String appDomain;
    private Integer treeOrder; //排序

    @Transient
    private List<AppFuncTree> children = Lists.newArrayList();

    public static Finder<Integer, AppFuncTree> finder = new Finder<>(AppFuncTree.class);

    public List<AppFuncTree> getChildren() {
        return Ebean.find(AppFuncTree.class).where().eq("parentId", this.getId()).orderBy("treeOrder asc").findList();
    }

}
